<?php


namespace App\Http\Responses;

use Illuminate\Support\Facades\Response as Res;


class Response
{
    /* private make response method */
    private static function __makeResponse(array $responseCode)
    {
        return Res::json([
            "code" => $responseCode["code"],
            "message" => $responseCode["message"]
        ]);
    }

    private static function __makeResourceResponse(array $responseCode, array $data)
    {
        return Res::json([
            "code" => $responseCode["code"],
            "message" => $responseCode["message"],
            "data" => [
                "count" => count($data),
                "content" => $data
            ]
        ]);
    }

    private static function __makeSingleResourceResponse(array $responseCode, array $data)
    {
        return Res::json([
            "code" => $responseCode["code"],
            "message" => $responseCode["message"],
            "data" => $data
        ]);
    }


    /* success result method */
    public static function success(array $responseCode = ResponseCode::SUCCESS)
    {
        return self::__makeResponse($responseCode);
    }

    public static function insert_success(array $data = [], array $responseCode = ResponseCode::INSERT_SUCCESS)
    {
        return self::__makeSingleResourceResponse($responseCode, $data);
    }

    public static function update_success(array $data = [], array $responseCode = ResponseCode::UPDATE_SUCCESS)
    {
        return self::__makeSingleResourceResponse($responseCode, $data);
    }

    public static function delete_success(array $data = [], array $responseCode = ResponseCode::DELETE_SUCCESS)
    {
        return self::__makeSingleResourceResponse($responseCode, $data);
    }


    /* error result method */
    public static function not_found(array $responseCode = ResponseCode::NOT_FOUND)
    {
        return self::__makeResponse($responseCode);
    }

    public static function insert_error(array $responseCode = ResponseCode::INSERT_ERROR)
    {
        return self::__makeResponse($responseCode);
    }

    public static function update_error(array $responseCode = ResponseCode::UPDATE_ERROR)
    {
        return self::__makeResponse($responseCode);
    }

    public static function delete_error(array $responseCode = ResponseCode::DELETE_ERROR)
    {
        return self::__makeResponse($responseCode);
    }

    public static function resource_success(array $data = [], array $responseCode = ResponseCode::SUCCESS)
    {
        return self::__makeResourceResponse($responseCode, $data);
    }

}